/**
 * Created by Intellij IDEA
 *
 * @author 王俊凯
 * @Date: 2023/2/27 20:20
 * @Version 1.0
 */
package com.eight.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.eight.dao.CarBrandDao;
import com.eight.pojo.TbBrand;
import com.eight.service.CarBrandService;
import com.eight.vo.CarVo;
import com.eight.vo.ComResult;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CarBrandServiceImpl implements CarBrandService {

    @Autowired
    private CarBrandDao carBrandDao;


    @Override
    public ComResult selectAllBrand(CarVo carVo) {
        Page<Object> page = PageHelper.startPage(carVo.getPageNum(), carVo.getPageSize());
        QueryWrapper<TbBrand> wrapper=null;
        if (carVo.getName() != null) {
            wrapper=new QueryWrapper<>();
            wrapper.like("name",carVo.getName());
        }

        List<TbBrand> tbBrands = carBrandDao.selectList(wrapper);
        PageInfo<TbBrand> pageInfo=new PageInfo<>(tbBrands);
        return new ComResult(2000,"查询成功",pageInfo);
    }

    @Override
    public ComResult selectAllBrand() {
        List<TbBrand> tbBrands = carBrandDao.selectList(null);
        return new ComResult(2000,"查询成功",tbBrands);
    }

    @Override
    public ComResult insert(TbBrand tbBrand) {
        int insert = carBrandDao.insert(tbBrand);
        return new ComResult(2000,"添加品牌",insert);
    }

    @Override
    public ComResult delete(int id) {
        int delete = carBrandDao.deleteById(id);
        return new ComResult(2000,"删除品牌",delete);
    }

    @Override
    public ComResult update(TbBrand tbBrand) {
        int update = carBrandDao.updateById(tbBrand);
        return new ComResult(2000,"修改品牌",update);
    }
}

